import React, { Component } from 'react';
import { Modal,Button  } from 'antd';
import PubSub from 'pubsub-js'
import './comment-item.css'

export default class CommentItem extends Component {
    constructor (props) {
        super(props)
        this.state={
          visible:false,
          delectindex:0
        }
    }
    showModal = (e) => {
      this.setState({delectindex:e.target.dataset.index})
      this.setState({
        visible: true,
      });
    }
    handleOk = (e) => {
      console.log(this.state.delectindex)
      this.setState({
        visible: false
      });
      PubSub.publish('要删除的index',this.state.delectindex)
    }
  
    handleCancel = () => {
      this.setState({
        visible: false,
      });
    }
  render() {
    return (
      <div className="list">
        <h5>{this.props.item.name}说：</h5>
        <p>{this.props.item.content}</p>
        <Button type="danger" className="delect" onClick={this.showModal} data-index={this.props.index}>删除</Button>
        <Modal
          title="提示框"
          visible={this.state.visible}
          onOk={this.handleOk}
          onCancel={this.handleCancel}
        >
          <p>你确定要删除这条评论吗</p>
        </Modal>
      </div>
    )
  }
}
